package com.asiainfo.dacp.datastash.broker.listener;

import com.asiainfo.dacp.core.BeanFactory;
import com.asiainfo.dacp.datastash.broker.tracelog.StashTraceLogFacade;
import com.asiainfo.dacp.datastash.broker.tracelog.StashTraceLogVo;
import com.asiainfo.dacp.datastash.broker.tracelog.StashTraceLoggerService;
import org.springframework.scheduling.annotation.Async;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * 监控轨迹日志
 *
 * @author MeiKefu
 * @date 2017-11-30
 */
public class BrokerTraceLogListener extends AbstractQueueListener {

    private int fetchSize = 20;
    /**
     *
     */
    @Async
    protected void handle(){
        int size = fetchSize;
        List<StashTraceLogVo> logList = null;
        StashTraceLogFacade stashTraceLogFacade = BeanFactory.getBean(StashTraceLogFacade.class);
        StashTraceLoggerService stashTraceLoggerService = BeanFactory.getBean(StashTraceLoggerService.class);
        while(size>0){
            StashTraceLogVo stashTraceLogVo = stashTraceLogFacade.getStashTraceLogVo();
            if(stashTraceLogVo==null){
                break;
            }
            if(logList==null){
                logList = new ArrayList<>(fetchSize);
            }
            logList.add(stashTraceLogVo);
        }
        //暂时注释
        //stashTraceLoggerService.persist(logList);
    }

    @Override
    protected int getIntervals(){
        return 5;
    }

}
